package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.GoodsPartitionMapper;
import com.weixing.mall.provider.model.domain.GoodsPartition;
import com.weixing.mall.provider.service.IGoodsPartitionService;
import com.weixing.mall.util.ListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @Author wx
 * @Date 2019/8/13 11:51
 * @Version 1.0
 */
/**
 * <p>
 * 商品模块-商品分区关联表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-20
 */
@Service
public class GoodsPartitionServiceImpl extends ServiceImpl<GoodsPartitionMapper, GoodsPartition> implements IGoodsPartitionService {
    @Autowired
    private GoodsPartitionMapper goodsPartitionMapper;

    @Override
    public void save(Long id, Long[] partitionId) {
        ArrayList<GoodsPartition> list = new ArrayList<GoodsPartition>();
        for(int i=0;i<partitionId.length;i++){
            GoodsPartition goodsPartition = new GoodsPartition();
            goodsPartition.setGoodsId(id);
            goodsPartition.setPartitionId(partitionId[i].intValue());
             list.add(i,goodsPartition);
        }
//        List<GoodsPartition> listPartition=goodsPartitionMapper.selectByGoodsId(id);
////        if(listPartition.size()==0){
////            goodsPartitionMapper.insertList(list);
////        }else {
////            goodsPartitionMapper.update(list);
////        }
        //先将原有的数据进行删除
        goodsPartitionMapper.deleteAllByGoods(list);
        //删除之后，在进行新增
        saveBatch(list, ListUtil.SIZE);

    }
}
